<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>加强金字塔</title>
</head>
<body>
<script>
    /*
    4. 定义一个函数用来在页面上输出一个由水平线构成的金字塔，要求该函数有一个参数，
    给参数赋值0就输出一个正金字塔，
    给参数赋值1就输出一个倒金字塔
     */
    function fun1(x) {
        if (x) {
            var colors = ["#FF0000", "#00ffg0", "#dFf0h0", "#Fh5f00", "#F5bd00", "#nfuf00", "#00tff", "#0Ffft0",];
            for (var i = 2; i <= 500; i += 10) {
                var res = Math.random() * colors.length;
                var number = Math.floor(res);
                document.write("<hr size='2' width='" + i + "' color='"+ colors[number]+ "'>");//加号拼接
            }
        } else {
            var colors = ["#FF0000", "#00ffg0", "#dFf0h0", "#Fh5f00", "#F5bd00", "#nfuf00", "#00tff", "#0Ffft0",];
            for (var i = 500; i >= 2; i -= 10) {
                var res = Math.random() * colors.length;
                var number = Math.floor(res);
                document.write("<hr size='2' width='" + i + "' color='"+ colors[number] +"'>");//加号拼接
            }

        }
    }
    fun1(0);


</script>
</body>
</html>